/*
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package blms.repository;

import java.io.Serializable;
import java.util.Collection;

import blms.domain.Identifiable;

/**
 * Abstract definition of a object repository. Instances may be used to load and
 * store objects from different sources.
 * 
 * @see Identifiable
 * 
 * @author João Arthur
 * @author Jonhnny Weslley
 * @author Thiago Emmanuel
 * @version 1.00, 21/04/2008
 * @since 1.0
 */
public interface Repository<E extends Identifiable> {

	/**
	 * Add the new object to this {@link Repository}
	 * 
	 * @param entity
	 *            the object to be added to this {@link Repository}
	 */
	void add(E entity);

	/**
	 * Update changes to an existing object from this {@link Repository}, if it
	 * is present
	 * 
	 * @param entity
	 *            the object to be updated from this {@link Repository}, if
	 *            present
	 */
	void update(E entity);

	/**
	 * Remove an existing object from this {@link Repository}, if it is present
	 * 
	 * @param entity
	 *            the object to be removed from this {@link Repository}, if
	 *            present
	 */
	void remove(E entity);

	/**
	 * Remove all objects from this {@link Repository}
	 */
	void removeAll();

	/**
	 * Returns the object to which the specified {@code id} is associated, or
	 * {@code null} if this {@link Repository} contains no object associated for
	 * the {@code id}
	 * 
	 * @see Identifiable#getId()
	 * 
	 * @param id
	 *            the id whose associated object is to be returned
	 * @return the value to which the specified {@code id} is associated, or
	 *         {@code null} if this {@link Repository} contains no object
	 *         associated for the {@code id}
	 */
	E get(Serializable id);

	/**
	 * Returns a {@link Collection} of the objects contained in this
	 * {@link Repository}
	 * 
	 * @return a collection of the objects contained in this {@link Repository}
	 */
	Collection<E> getAll();

	/**
	 * Returns <tt>true</tt> if this {@link Repository} contains an object
	 * with the specified id
	 * 
	 * @see Identifiable#getId()
	 * 
	 * @param id
	 *            the object id
	 * @return <tt>true</tt> if this {@link Repository} contains an object
	 *         with the specified id
	 */
	boolean contains(Serializable id);

}
